const path = require("path")

const minify =
	process.env.NODE_ENV === "development"
		? false
		: {
				collapseWhitespace: true,
				removeComments: true,
				removeRedundantAttributes: true,
				removeScriptTypeAttributes: true,
				removeStyleLinkTypeAttributes: true,
				useShortDoctype: true,
				minifyCSS: true,
				minifyJS: true,
		  }
function resolve(dir) {
	return path.resolve(__dirname, dir)
}

module.exports = {
	publicPath: process.env.NODE_ENV === "production" ? "/admin/" : "/",
	pages: {
		index: {
			entry: "src/main.js",
			template: "public/index.html",
			filename: "index.html",
			chunks: ["chunk-vendors", "chunk-common", "index"],
			minify,
		},
	},
	devServer: {
		port: 8888,
		proxy: {
			"/api/": {
				target: process.env.VUE_APP_ROOT_URL_ENV,
				changeOrigin: true,
				ws: true,
				pathRewrite: {
					"^/api/": "",
				},
			},
		},
	},
	lintOnSave: false,
	runtimeCompiler: true,
	productionSourceMap: false,
	chainWebpack: config => {
		config.resolve.alias.set("@", resolve("src"))
		// set svg-sprite-loader
		config.module
			.rule("svg")
			.exclude.add(resolve("src/icons"))
			.end()
		config.module
			.rule("icons")
			.test(/\.svg$/)
			.include.add(resolve("src/icons"))
			.end()
			.use("svg-sprite-loader")
			.loader("svg-sprite-loader")
			.options({
				symbolId: "icon-[name]",
			})
			.end()
	},
}
